package servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import service.TeacherService;

/**
 * Servlet implementation class ZxServlet
 */
@WebServlet("/zx")
public class ZxServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
	private TeacherService teacherService=new TeacherService();

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");
		String method = request.getParameter("method");
		if("teacher".contentEquals(method)) {
			teacher(request,response);
		}
	}

	private void teacher(HttpServletRequest request, HttpServletResponse response) throws IOException {
		 String idStr = request.getParameter("id");
		 Integer id=Integer.valueOf(idStr);
		 teacherService.delete(id);
		response.sendRedirect("login");
		
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
